package com.panopset.swing;

import static com.panopset.Util.dump;

import java.awt.BorderLayout;

import javax.swing.JLabel;
import javax.swing.JScrollPane;

import com.panopset.centralen.SysInfo;
import com.panopset.gui.TPanel;
import com.panopset.gui.TTextArea;

/**
 *
 * System information panel.
 *
 * @author Karl Dinwiddie
 *
 */
public final class SysInfoPanel {

    /**
     * Sleep cycle is one second, or 1000 milliseconds.
     */
    public static final int SLEEP_CYCLE = 1000;

    /**
     * Swing panel.
     */
    private TPanel gui;

    /**
     * @return Swing system information panel.
     */
    public TPanel getGui() {
        if (gui == null) {
            gui = new TPanel(new BorderLayout());
            TTextArea ta = new TTextArea(dump(SysInfo.getMap()));
            ta.setEditable(false);
            gui.add(BorderLayout.CENTER, new JScrollPane(ta));
            try {
                String nm = com.panopset.Util.getSourceName(getClass());
                gui.add(BorderLayout.NORTH, new JLabel("Loaded from " + nm));
            } catch (Exception e) {
                ta.setText(com.panopset.Util.getStackTrace(e));
            }
        }
        return gui;
    }
}
